package com.example.user.controller;


import com.example.user.common.Result;
import com.example.user.entity.CommunityActivity;
import com.example.user.service.HomeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "http://localhost:8080")
public class HomeController {


    @Autowired
    private HomeService homeService;

    @GetMapping("/selectActivtyPage")
    public Result<PageInfo> selectActivtyPage(@RequestParam Integer pageNumber,@RequestParam Integer pageSize) {

        PageHelper.startPage(pageNumber, pageSize);
       List<CommunityActivity> communityActivityList= homeService.selectActivtyPage();
       PageInfo<CommunityActivity> pageInfo=new PageInfo<>(communityActivityList);
       return Result.success(pageInfo);
    }

    @GetMapping("/selectActivityByName")
    public Result<PageInfo> selectActivityByName(@RequestParam String activityName){
        PageHelper.startPage(1, 10);
       List<CommunityActivity> communityActivityList= homeService.selectActivityByName(activityName);
       PageInfo<CommunityActivity> pageInfo=new PageInfo<>(communityActivityList);
        return Result.success(pageInfo);

    }

    @GetMapping("/selectActivtyByType")
    public Result<PageInfo> selectActivtyByType(@RequestParam String activityType){

        PageHelper.startPage(1, 10);
       List<CommunityActivity> communityActivityList= homeService.selectActivtyByType(activityType);
       PageInfo<CommunityActivity> pageInfo=new PageInfo<>(communityActivityList);
       return Result.success(pageInfo);
    }

    @GetMapping("/selectActivityByLocation")
    public Result<PageInfo> selectActivityByLocation(@RequestParam String activityLocation){

        PageHelper.startPage(1, 10);
      List<CommunityActivity> communityActivityList=  homeService.selectActivityByLocation(activityLocation);
      PageInfo<CommunityActivity> pageInfo=new PageInfo<>(communityActivityList);
      return Result.success(pageInfo);
    }
}
